package com.neusoft.yuejian_01.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.neusoft.yuejian_01.activity.GiftDetailActivity;
import com.neusoft.yuejian_01.R;
import com.neusoft.yuejian_01.javabean.GiftBean;
import com.neusoft.yuejian_01.model.ConstPhoto;
import com.neusoft.yuejian_01.viewHolder.GiftListViewHolder;

import java.util.ArrayList;
import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by MARIA on 2017/10/12.
 */

public class GiftListAdapter  extends RecyclerView.Adapter {

    private List<GiftBean> GiftList = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;//使用了LayoutInflater来载入布局界面

    public GiftListAdapter(Context context, List<GiftBean> GiftList) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.GiftList.addAll(GiftList);

    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_giftlist, parent, false);
        GiftListViewHolder holder = new GiftListViewHolder(itemView);
        return holder;

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        GiftListViewHolder giftListViewHolder = (GiftListViewHolder) holder;
        final GiftBean giftBean = GiftList.get(position);
        String G_sportNb=giftBean.getG_sportnb();

        String pic =  ConstPhoto.BASE_URL+ConstPhoto.GiftFile + giftBean.getG_pic();

        Picasso.with(context)
                .load(pic)
                .into(giftListViewHolder.g_pic);

        GiftListViewHolder.g_sport.setText(G_sportNb);
        giftListViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Bundle bundle=new Bundle();
                bundle.putInt("g_id",giftBean.getG_id());
                bundle.putString("g_name",giftBean.getG_name());
                bundle.putString("g_values",giftBean.getG_values());
                bundle.putString("g_pic",giftBean. getG_pic());
                Intent intent = new Intent(context, GiftDetailActivity.class);
                intent.putExtras(bundle);
                context.startActivity(intent);

                //启动新的activity(帖子详情)
            }
        });



    }

    @Override
    public int getItemCount() {
        {
            return GiftList.size();
        }
    }

}